package b1.mobile.blackberry.util;

import java.io.IOException;

import javax.microedition.content.ContentHandler;
import javax.microedition.content.ContentHandlerException;
import javax.microedition.content.Invocation;
import javax.microedition.content.Registry;

import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.device.api.content.BlackBerryContentHandler;

public class OpenFileUtil {
	public static void openAddressInBrowser(String address){
		BrowserSession browserSession = Browser.getDefaultSession();
        Browser.getDefaultSession();
        browserSession.displayPage(address);
	}
	
	public static void openFile(String filePath){
		try{
			Invocation invocation = new  Invocation(filePath);
			invocation.setAction(ContentHandler.ACTION_OPEN);
//			Registry registry = Registry.getRegistry("net.rim.device.api.content.BlackBerryContentHandler");
			Registry registry = Registry.getRegistry("b1.mobile.blackberry.util.OpenFileUtil");
			registry.invoke(invocation);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ContentHandlerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void openWithInovke(String attachment){
		try{
			Invocation invocation = new Invocation(attachment,null, BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER);
			
			Registry registry = Registry.getRegistry(net.rim.device.api.system.Application.getApplication().getClass().getName());
			
			registry.invoke(invocation);
			
		} catch (IOException e){
			
		}        
	}
}
